package com.wms.runtestcase;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import org.apache.http.client.ClientProtocolException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.wms.business.LoginBusiness;
import com.wms.business.PDBusiness;
import com.wms.client.BuildHttpClient;
import com.wms.domain.PDParam;
import com.wms.domain.PDParamPath;

public class TestPDBusiness {
	public static PDBusiness bs = new PDBusiness();
	public static String reviewId;
	public static Logger logger = LoggerFactory.getLogger(TestPDBusiness.class);
	
	@BeforeClass
	public static void beforeClass() throws ClientProtocolException, IOException {
		LoginBusiness.Login();
	}
	@AfterClass
	public static void afterClass() throws IOException {
		BuildHttpClient.closeClient();
	}	
	
//------------------------------------case---------------------------------	
	/**
	 * case标题：test半盲盘盘点数量与库存一致是否可发起复盘
	 * 预期结果：msg:盘点差异数量等于0或已盘点完毕，禁止发起复盘检查！
	 * true  false
	 */
	@Test(enabled = false)
	public static void testOnePdT() throws Exception {
		logger.info("########case标题：test半盲盘盘点数量与库存一致是否可发起复盘#######");
		//创建盘点单
		bs.createMangPD();
		// 一盘数量与库存一致
		reviewPD(13,1);
		//发起复盘
		List<String> reviewIds = Arrays.asList(reviewId);
		bs.recheck(reviewIds, 0);
	}
	/**
	 * case标题：一盘盘盈
	 * 预期结果：校验一盘差异数
	 * 
	 */
	@Test(enabled = false)
	public static void testOnePdY() throws Exception {
		logger.info("########case标题：一盘盘盈#######");
		//创建盘点单
		bs.createMangPD();
		// 一盘盘盈
		reviewPD(15,1);
	}
	
	/**
	 * case标题：一盘盘亏,订单占用数为12
	 * 预期结果：校验一盘差异数，提示盘点数不能小于订单占用数
	 * 
	 */
	@Test(enabled = true)
	public static void testOnePdK() throws Exception {
		logger.info("########case标题：一盘盘亏,订单占用数为12#######");	
		//创建盘点单
		bs.createMangPD();
		// 一盘盘亏
		reviewPD(12,1);
		//中断盘点
		List<String> reviewIds = Arrays.asList(reviewId);
		interrupt(reviewIds);
	}
	

	/**
	 * 
	 * test半盲盘盘点数量(盘盈),进行二盘
	 * @throws Exception 
	 */
	@Test(enabled = false)
	public static void testTwoPdY() throws Exception {
		logger.info("########case标题：test半盲盘盘点数量(盘盈),进行二盘#######");
		//创建盘点单
		bs.createMangPD();
		// 一盘盘亏		
		TestPDBusiness.reviewPD(12,1);
		// 进行二盘复盘
		List<String> reviewIds = Arrays.asList(reviewId);
		bs.recheck(reviewIds, 0);
		TestPDBusiness.reviewPD(12,2);

	}
	/**
	 * 
	 * test半盲盘盘点数量(盘盈),进行三盘
	 * @throws Exception 
	 */
	@Test(enabled = false)
	public static void testThreePdY() throws Exception {
		logger.info("########case标题：test半盲盘盘点数量(盘盈),进行三盘#######");
		//创建盘点单
		bs.createMangPD();
		// 一盘盘盈		
		TestPDBusiness.reviewPD(14,1);
		// 进行二盘盘亏
		List<String> reviewIds = Arrays.asList(reviewId);
		bs.recheck(reviewIds, 0);
		TestPDBusiness.reviewPD(12,2);
		//进行三盘		
		bs.recheck(reviewIds, 0);
		TestPDBusiness.reviewPD(15,3);
	}
	
	
	
	
	
	
	
//--------------------------------------------------公共方法-------------------------------------------	
	/**
	 * @throws IOException 
	 * @throws ClientProtocolException 
	 * 创建盘点单
	 * 
	 */
	@Test(enabled = false)
	public static void  creatCheck() throws ClientProtocolException, IOException{
		bs.createMangPD();//创建盘点单
	}
	
	
	/**
	 * 中断盘点
	 * @throws IOException 
	 * @throws ClientProtocolException 
	 * 
	 */
	public static void interrupt(List<String> reviewIds) throws ClientProtocolException, IOException{	
		bs.interrupt(reviewIds);
	}
	
	
	/**
	 * 公共的盘点方法
	 * 1.获取reviewId
	 * 2.获取areaId
	 * 3.将reviewId与areaId传入领取Controller领取盘点
	 * 4.进行扫码
	 * 5.确认
	 * 6.再次确认
	 * 
	 * @Param  CheckCount   盘点数
	 * @param  PdNumber		n盘
	 * @throws Exception 
	 */
	public static  void reviewPD(int CheckCount,int PdNumber) throws Exception {
		
		reviewId = bs.getReviewid();
//		AssertBase.assertEquals(reviewId, DBBase.getReview_Id());
		String areaId = bs.getareaId(reviewId);	
		PDParam param = bs.receivePD(reviewId, areaId);
		bs.Scan_code(param, PDParamPath.bmType);
		switch(PdNumber){
		case 1: 
			bs.affirm1(param, CheckCount);
			bs.affirm2(param, CheckCount);
			break;
		case 2:
			bs.affirm1(param, CheckCount);
			break;
		case 3:
			bs.affirm1(param, CheckCount);
			break;
		default :
			System.out.println("最多只可以进行三盘");
			break;
		}
	}

	
}
